<!--
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<kd-card role="table"
         [hidden]="isHidden()">
  <div title
       fxLayout="row"
       i18n>Persistent Volume Claims</div>
  <div description><span class="kd-muted-light"
          i18n>Items:&nbsp;</span>{{ totalItems }}</div>
  <div actions>
    <kd-card-list-filter></kd-card-list-filter>
  </div>

  <div content
       [hidden]="showZeroState()">
    <div kdLoadingSpinner
         [isLoading]="isLoading"></div>

    <mat-table [dataSource]="getData()"
               [trackBy]="trackByResource"
               matSort
               matSortActive="created"
               matSortDisableClear
               matSortDirection="asc">
      <ng-container matColumnDef="statusicon">
        <mat-header-cell *matHeaderCellDef></mat-header-cell>
        <mat-cell *matCellDef="let pvc">
          <mat-icon [ngClass]="getStatus(pvc).iconClass"
                    [matTooltip]="getStatus(pvc).iconTooltip">{{ getStatus(pvc).iconName }}</mat-icon>
        </mat-cell>
      </ng-container>

      <ng-container matColumnDef="name">
        <mat-header-cell *matHeaderCellDef
                         mat-sort-header
                         disableClear="true"
                         class="col-stretch-l"
                         i18n>Name</mat-header-cell>
        <mat-cell *matCellDef="let pvc"
                  class="col-stretch-l">
          <a [routerLink]="getDetailsHref(pvc.objectMeta.name, pvc.objectMeta.namespace)"
             queryParamsHandling="preserve">
            {{ pvc.objectMeta.name }}
          </a>
        </mat-cell>
      </ng-container>

      <ng-container *ngIf="shouldShowColumn('namespace')"
                    matColumnDef="namespace">
        <mat-header-cell *matHeaderCellDef
                         class="col-stretch-l col-min-90"
                         i18n>Namespace</mat-header-cell>
        <mat-cell *matCellDef="let pvc"
                  class="col-stretch-l col-min-90">{{ pvc.objectMeta.namespace }}</mat-cell>
      </ng-container>

      <ng-container matColumnDef="labels">
        <mat-header-cell *matHeaderCellDef
                         class="col-stretch-xl"
                         i18n>Labels</mat-header-cell>
        <mat-cell *matCellDef="let pvc"
                  class="col-stretch-xl">
          <kd-chips [map]="pvc.objectMeta.labels"></kd-chips>
        </mat-cell>
      </ng-container>

      <ng-container matColumnDef="status">
        <mat-header-cell *matHeaderCellDef
                         mat-sort-header
                         disableClear="true"
                         class="col-stretch-s"
                         i18n>Status</mat-header-cell>
        <mat-cell *matCellDef="let pvc"
                  class="col-stretch-s">{{ pvc.status }}</mat-cell>
      </ng-container>

      <ng-container matColumnDef="volume">
        <mat-header-cell *matHeaderCellDef
                         class="col-stretch-xl"
                         i18n>Volume</mat-header-cell>
        <mat-cell *matCellDef="let pvc"
                  class="col-stretch-xl">
          <ng-container *ngIf="pvc.volume">
            <a [routerLink]="getVolumeHref(pvc.volume)"
               queryParamsHandling="preserve">{{ pvc.volume }}</a>
          </ng-container>
          <ng-container *ngIf="!pvc.volume">-</ng-container>
        </mat-cell>
      </ng-container>

      <ng-container matColumnDef="capacity">
        <mat-header-cell *matHeaderCellDef
                         class="col-stretch-s"
                         i18n>Capacity</mat-header-cell>
        <mat-cell *matCellDef="let pvc"
                  class="col-stretch-s">
          <ng-container *ngIf="pvc?.capacity?.storage">{{ pvc.capacity.storage }}</ng-container>
          <ng-container *ngIf="!pvc?.capacity?.storage">-</ng-container>
        </mat-cell>
      </ng-container>

      <ng-container matColumnDef="accmodes">
        <mat-header-cell *matHeaderCellDef
                         class="col-stretch-l"
                         i18n>Access Modes</mat-header-cell>
        <mat-cell *matCellDef="let pvc"
                  class="col-stretch-l">
          <kd-chips [map]="pvc.accessModes"></kd-chips>
        </mat-cell>
      </ng-container>

      <ng-container matColumnDef="storagecl">
        <mat-header-cell *matHeaderCellDef
                         class="col-stretch-l"
                         i18n>Storage Class</mat-header-cell>
        <mat-cell *matCellDef="let pvc"
                  class="col-stretch-l">
          <ng-container *ngIf="pvc?.storageClass">{{ pvc.storageClass }}</ng-container>
          <ng-container *ngIf="!pvc?.storageClass">-</ng-container>
        </mat-cell>
      </ng-container>

      <ng-container matColumnDef="created">
        <mat-header-cell *matHeaderCellDef
                         mat-sort-header
                         disableClear="true"
                         class="col-stretch-m"
                         i18n>Created</mat-header-cell>
        <mat-cell *matCellDef="let pvc"
                  class="col-stretch-m">
          <kd-date [date]="pvc.objectMeta.creationTimestamp"
                   relative></kd-date>
        </mat-cell>
      </ng-container>

      <ng-container *ngFor="let col of getActionColumns()"
                    [matColumnDef]="col.name">
        <mat-header-cell *matHeaderCellDef></mat-header-cell>
        <mat-cell *matCellDef="let pvc">
          <kd-dynamic-cell [component]="col.component"
                           [resource]="pvc"></kd-dynamic-cell>
        </mat-cell>
      </ng-container>

      <mat-header-row *matHeaderRowDef="getColumns()"></mat-header-row>
      <mat-row *matRowDef="let row; columns: getColumns()"></mat-row>
    </mat-table>

    <div [hidden]="totalItems <= itemsPerPage">
      <mat-paginator [length]="totalItems"
                     [pageSize]="itemsPerPage"
                     hidePageSize
                     showFirstLastButtons></mat-paginator>
    </div>
  </div>

  <div content
       [hidden]="!showZeroState()">
    <kd-list-zero-state></kd-list-zero-state>
  </div>
</kd-card>
